<?php
	// Do not delete these lines
	if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
		die ('Please do not load this page directly. Thanks!');
?>

<?php if ( !empty($post->post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
	<p class="errortip">
		<?php _e('Enter your password to view comments.', 'eachBlue'); ?>
	</p>
<?php return; endif; ?>

<?php
	$trackbacks = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND (comment_type = 'pingback' OR comment_type = 'trackback') ORDER BY comment_date", $post->ID));
?>

<!-- Begin comments -->
<?php if ($comments || comments_open()) : ?>
<div id="comments">
  <!-- Begin title -->
  <div class="commenttitle">
    <h3>
	  <ul>
	    <li id="tabcomment1" onclick="setTab('tabcomment',1,2)" class="current"><?php _e('Comments', 'eachBlue'); echo (' (' . (count($comments)-count($trackbacks)) . ')'); ?>
		</li>
		<li id="tabcomment2" onclick="setTab('tabcomment',2,2)"><?php _e('Trackbacks', 'eachBlue'); echo (' (' . count($trackbacks) . ')'); ?></li>
	  </ul>
	  <?php if(comments_open()) : ?>
		<span id="gotocomment"><a href="#respond"><?php _e('Leave a comment', 'eachBlue'); ?></a></span>
	  <?php endif; ?>
	  <?php if(pings_open()) : ?>
		<span id="gotoaddtrackback"><a href="<?php trackback_url(); ?>"><?php _e('Trackback', 'eachBlue'); ?></a></span>
	  <?php endif; ?>
	</h3>   
  </div>
  <!-- End title -->
  <!-- Begin commentlist -->
  <div id="contabcomment1">
  <?php if(have_comments()) : ?>
  <div id="commentlist">
  <ul class="parents">
  <?php wp_list_comments(array(
   'style' => 'ul',
   'type' => 'comment',
   'callback' => 'custom_comments',
   'end-callback' => 'custom_comments_end'
   )
   ); ?>
  </ul>
  </div>
  <?php else : ?>
  <p class="msgtip msgbox">
  <?php _e('No comments yet.', 'eachBlue'); ?>
  </p>
  <?php endif; ?>
  <!-- Begin commentpages -->
  <?php
	if (get_option('page_comments')) {
		$comment_pages = paginate_comments_links('echo=0');
		if ($comment_pages) {
?>
	<div id="commentnavi">		
	   <em><?php _e('Comment pages', 'eachBlue'); ?>:</em><span><?php echo $comment_pages; ?></span>
	</div>
<?php
		}
	}
?>
<!-- End commentpages -->
</div>
<!-- End commentlist -->
<!-- Begin trackbacklist -->
<div id="contabcomment2" class="nodis">
  <?php if ($trackbacks) : ?>
  <ul id="trackbacklist">
  <?php foreach ($trackbacks as $comment) : ?>
  <li id="comment-<?php comment_ID( ); ?>">
  <small><?php comment_date() ?><?php comment_time() ?></small><?php comment_author_link(); ?>
  </li>
  <?php endforeach; ?>
  </ul>
  <?php else : ?>
  <p class="msgtip msgbox">
  <?php _e('No trackback yet.', 'eachBlue'); ?>
  </p>
  <?php endif; ?>
</div>
<!-- End trackbacklist -->
</div>
<?php endif; ?>
<!-- End comments -->

<!-- Begin postcomment -->
<?php if (!comments_open()) : // If comments are closed. ?>
	<p class="msgtip msgbox">
	  <?php _e('Comments are closed.', 'eachBlue'); ?>
	</p>
<?php elseif ( get_option('comment_registration') && !$user_ID ) : // If registration required and not logged in. ?>
	<p class="msgtip msgbox">
	 <?php if (function_exists('wp_login_url')) {$login_link = wp_login_url();} else { $login_link = site_url('wp-login.php', 'login'); } ?>
     <?php printf(__('You must be <a href="%s">logged in</a> to post a comment.', 'eachBlue'), $login_link); ?>
   </p>
<?php else : ?>

  <div id="respond" class="postcomment">
	<div id="postcommenttitle">
	 <span id="commentreply"><?php comment_form_title(__('Leave a Reply.','eachBlue'), __('Leave a Reply to %s.','eachBlue'), true); ?></span>
     <span id="cancelcommentreply"><?php cancel_comment_reply_link(__('Click here to cancel reply.','eachBlue')) ?></span>
	</div>
	<div id="postcommentbody">
	<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
	 <?php if ($user_ID) : ?>
	 <?php if (function_exists('wp_logout_url')) {$logout_link = wp_logout_url();} else { $logout_link = site_url('wp-login.php?action=logout', 'login'); } ?>
	 <div class="logintitle">
	 <?php _e('Logged in as', 'eachBlue'); ?> <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><b><?php echo $user_identity; ?></b></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php _e('Log out of this account', 'eachBlue'); ?>"><?php _e('Logout &raquo;', 'eachBlue'); ?></a>
	 </div>
	<?php else : ?>
	<?php if ( $comment_author != "" ) : ?>
	<div class="logintitle">
	<?php printf(__('Welcome back <strong>%s</strong>.', 'eachBlue'), $comment_author) ?>
	<span id="show_author_info">
	<a href="javascript:void(0);" onclick="MGJS.setStyleDisplay('author_info','');MGJS.setStyleDisplay('show_author_info','none');MGJS.setStyleDisplay('hide_author_info','');"><?php _e('Change &raquo;'); ?></a>
	</span>
	<span id="hide_author_info">
	<a href="javascript:void(0);" onclick="MGJS.setStyleDisplay('author_info','none');MGJS.setStyleDisplay('show_author_info','');MGJS.setStyleDisplay('hide_author_info','none');"><?php _e('Close &raquo;'); ?></a>
	</span>
	</div>
	<?php endif; ?>

	<div id="author_info">
	<div class="userinfo">
	<ul>
	<li>
	<input type="text" name="author" id="author" class="textfield" value="<?php echo $comment_author; ?>" size="24" tabindex="1" />
	<label for="author" class="small"><?php _e('Name', 'eachBlue'); ?> <?php if ($req) _e('(required)', 'eachBlue'); ?></label>
	</li>
	<li>
	<input type="text" name="email" id="email" class="textfield" value="<?php echo $comment_author_email; ?>" size="24" tabindex="2" />
	<label for="email" class="small"><?php _e('E-Mail (will not be published)', 'eachBlue');?> <?php if ($req) _e('(required)', 'eachBlue'); ?></label>
	</li>
	<li>
	<input type="text" name="url" id="url" class="textfield" value="<?php echo $comment_author_url; ?>" size="24" tabindex="3" />
	<label for="url" class="small"><?php _e('Website', 'eachBlue'); ?></label>
	</li>
	</ul>
	</div>
	</div>

	<?php if ( $comment_author != "" ) : ?>
	<script type="text/javascript">MGJS.setStyleDisplay('hide_author_info','none');MGJS.setStyleDisplay('author_info','none');</script>
	<?php endif; ?>

	<?php endif; ?>

	<!-- comment input -->
	<div id="postcommenttext">
		<textarea name="comment" id="comment" tabindex="4" rows="8"></textarea>
	</div>

	<!-- comment submit and rss -->
	<div id="submitbox">
	<span>
	<input name="submit" type="submit" id="submit" class="postcommentbutton" tabindex="5" value="" />
	<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
	<?php comment_id_fields(); ?>
	</span>
	<a class="feed" href="<?php bloginfo('comments_rss2_url'); ?>"><?php _e('Subscribe to comments feed', 'eachBlue'); ?></a>
	</div>
	<?php do_action('comment_form', $post->ID); ?>
	</form>
	</div>
  </div>
<?php endif; ?>
<!-- End postcomment -->